<?php
/**
 * Library Of Shared Code (LOSC)
 *
 * LICENSE
 *
 * This source file is subject to the New BSD License that is bundled
 * with this package in the file LICENSE.txt.
 *
 * @category   LOSC Framework
 * @package    Validators
 * @copyright  Copyright (c) 2008 Robin Skoglund (http://robinsk.net/)
 * @license    http://creativecommons.org/licenses/BSD/  New BSD License
 */

/**
 * Validator for checking that a string is a valid timezone identifier
 *
 * @category   LOSC Framework
 * @package    Validate
 * @copyright  Copyright (c) 2008 Robin Skoglund (http://robinsk.net/)
 * @license    http://creativecommons.org/licenses/BSD/  New BSD License
 */
class Losc_Validate_Timezone extends Zend_Validate_Abstract
{
    const NOT_TIMEZONE = 'notTimezone';

    /**
     * Error messages
     * 
     * @var array
     */
    protected $_messageTemplates = array(
        self::NOT_TIMEZONE => '"%value%" does not appear to be a timezone identifier'
    );
    
    /**
     * Defined by Zend_Validate_Interface
     *
     * Returns true if and only if $value is a valid timezone identifier
     * 
     * @link http://php.net/timezone_identifiers_list
     * 
     * @param  string $value
     * @return boolean
     */
    public function isValid($value)
    {
        $this->_setValue($value);

        if (!in_array($value, timezone_identifiers_list())) {
            $this->_error();
            return false;
        }

        return true;
    }
}
